﻿Imports System.Drawing.Drawing2D

Public Class Renderer
    Inherits ToolStripProfessionalRenderer

    Protected Overrides Sub OnRenderToolStripBackground(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
    End Sub

    Protected Overrides Sub OnRenderToolStripBorder(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
        If Not TypeOf e.ToolStrip Is ToolStripDropDown Then Exit Sub
        MyBase.OnRenderToolStripBorder(e)
    End Sub

    Sub DrawItem(ByVal G As Graphics, ByVal R As Rectangle, ByVal Pressed As Boolean, ByVal Selected As Boolean)
        G.SmoothingMode = SmoothingMode.HighQuality
        G.PixelOffsetMode = PixelOffsetMode.None
        R.Offset(-R.Left, -R.Top)
        R.Width -= 1 : R.Height -= 1
        If Pressed Then
            G.FillRoundRect(R, New SolidBrush(SystemColors.Highlight.Whiten(0.3)), 3)
            G.DrawRoundRect(R, New Pen(SystemColors.Highlight.Blacken(0)), 3)
            R.Inflate(-1, -1)
            G.DrawRoundRect(R, New Pen(SystemColors.Highlight.Whiten(0.4)), 2)
        ElseIf Selected Then
            G.FillRoundRect(R, New SolidBrush(SystemColors.Highlight.Whiten(0.6)), 3)
            G.DrawRoundRect(R, New Pen(SystemColors.Highlight.Blacken(0)), 3)
            R.Inflate(-1, -1)
            G.DrawRoundRect(R, New Pen(SystemColors.Highlight.Whiten(0.7)), 2)
        End If
    End Sub

    Protected Overrides Sub OnRenderButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        DrawItem(e.Graphics, e.Item.Bounds, e.Item.Pressed, e.Item.Selected)
    End Sub

    Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        DrawItem(e.Graphics, e.Item.Bounds, e.Item.Pressed, e.Item.Selected)
    End Sub

    Protected Overrides Sub OnRenderSeparator(ByVal e As System.Windows.Forms.ToolStripSeparatorRenderEventArgs)
        Dim R = e.Item.Bounds
        R.Offset(-R.Left, -R.Top)
        If e.Vertical Then
            R.Inflate(0, -4)
            e.Graphics.DrawLine(New Pen(Color.FromArgb(64, Color.Black)), R.Left + R.Width \ 2, R.Top, R.Left + R.Width \ 2, R.Bottom)
            e.Graphics.DrawLine(New Pen(Color.FromArgb(64, Color.White)), R.Left + R.Width \ 2 + 1, R.Top, R.Left + R.Width \ 2 + 1, R.Bottom)
        Else
            R.Inflate(-4, 0)
            e.Graphics.DrawLine(New Pen(Color.FromArgb(64, Color.Black)), R.Left, R.Top + R.Height \ 2, R.Right, R.Top + R.Height \ 2)
            e.Graphics.DrawLine(New Pen(Color.FromArgb(64, Color.White)), R.Left, R.Top + R.Height \ 2 + 1, R.Right, R.Top + R.Height \ 2 + 1)
        End If
    End Sub

    Protected Overrides Sub OnRenderToolStripPanelBackground(ByVal e As System.Windows.Forms.ToolStripPanelRenderEventArgs)
        MyBase.OnRenderToolStripPanelBackground(e)
        If e.ToolStripPanel.Bounds.Width = 0 OrElse e.ToolStripPanel.Bounds.Height = 0 Then Exit Sub
        e.Graphics.FillRectangle(New LinearGradientBrush(e.ToolStripPanel.Bounds, Color.White, Color.FromArgb(208, 224, 255), LinearGradientMode.Vertical), e.ToolStripPanel.Bounds)
    End Sub

    Protected Overrides Sub OnRenderToolStripContentPanelBackground(ByVal e As System.Windows.Forms.ToolStripContentPanelRenderEventArgs)
        e.Graphics.Clear(Color.Blue)
        'e.Graphics.FillRectangle(New LinearGradientBrush(e.ToolStripContentPanel.Bounds, Color.White, Color.Blue, LinearGradientMode.Vertical), e.ToolStripContentPanel.Bounds)
    End Sub

End Class
